/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyecto.modelado;

import com.proyecto.datos.EntityMateria;
import java.util.ArrayList;

/**
 *
 * @author mario
 */
public class Materia {

    public Materia() {
    }

    public ArrayList MostrarMaterias() {
        ArrayList arry = new ArrayList();
        String cadenaSQL = "select m.id_materia, m.cod_asignatura,m.nombre_materia,m.PLAN_id_plan, p.nombre_plan "
                + "from MATERIA m inner join PLAN p on m.PLAN_id_plan=p.id_plan;";

        EntityMateria entMate = new EntityMateria();
        arry = entMate.EjecutarConsulta(cadenaSQL);
        entMate = null;

        return arry;

    }
    
     public ArrayList MostrarMaterias_Param_Plan(int id_plan) {
        ArrayList arry = new ArrayList();
        String cadenaSQL = "select m.id_materia, m.cod_asignatura,m.nombre_materia,m.PLAN_id_plan, p.nombre_plan "
                + "from MATERIA m inner join PLAN p on m.PLAN_id_plan=p.id_plan "
                + "where m.PLAN_id_plan="+id_plan+";";

        EntityMateria entMate = new EntityMateria();
        arry = entMate.EjecutarConsulta(cadenaSQL);
        entMate = null;

        return arry;

    }

    public ArrayList MostrarMateriasPlan04() {
        ArrayList arry = new ArrayList();
        String cadenaSQL = "select m.id_materia,m.cod_asignatura,m.nombre_materia,m.PLAN_id_plan, p.nombre_plan "
                + "from MATERIA m, PLAN p "
                + "where m.PLAN_id_plan = 1 and m.PLAN_id_plan=p.id_plan";
        EntityMateria entMate = new EntityMateria();
        arry = entMate.EjecutarConsulta(cadenaSQL);
        entMate = null;

        return arry;
    }

    public ArrayList MostrarMateriasPlan10() {
        ArrayList arry = new ArrayList();
        String cadenaSQL = "select m.id_materia,m.cod_asignatura,m.nombre_materia,m.PLAN_id_plan, p.nombre_plan "
                + "from MATERIA m, PLAN p "
                + "where m.PLAN_id_plan = 2 and m.PLAN_id_plan=p.id_plan";
        EntityMateria entMate = new EntityMateria();
        arry = entMate.EjecutarConsulta(cadenaSQL);
        entMate = null;

        return arry;
    }

    public String InsertarMateria(String cod_asignatura, String nombre, int id_plan) {
        String cadenaSQL;
        String msj;

        cadenaSQL = "insert into MATERIA (cod_asignatura,nombre_materia,PLAN_id_plan) "
                + "values ('" + cod_asignatura + "','" + nombre + "'," + id_plan + ");";
        EntityMateria entMate = new EntityMateria();
        msj = entMate.EjecutarComando(cadenaSQL);
        entMate = null;

        return msj;


    }
    
    
    public ArrayList MostrarMateriasPlan_I_Alumno(int id_plan) {
        ArrayList arry = new ArrayList();
        String cadenaSQL = "select m.id_materia,m.cod_asignatura,m.nombre_materia,m.PLAN_id_plan, p.nombre_plan "
                + "from MATERIA m, PLAN p "
                + "where m.PLAN_id_plan = "+id_plan+" and m.PLAN_id_plan=p.id_plan";
        EntityMateria entMate = new EntityMateria();
        arry = entMate.EjecutarConsulta(cadenaSQL);
        entMate = null;

        return arry;
    }
    
    public ArrayList MostrarMateriasPlan_U1(int id_plan) {
        ArrayList arry = new ArrayList();
        String cadenaSQL = "select m.id_materia,m.cod_asignatura,m.nombre_materia,m.PLAN_id_plan, p.nombre_plan "
                + "from MATERIA m, PLAN p "
                + "where m.PLAN_id_plan = "+id_plan+" and m.PLAN_id_plan=p.id_plan";
        EntityMateria entMate = new EntityMateria();
        arry = entMate.EjecutarConsulta(cadenaSQL);
        entMate = null;

        return arry;
    }
    
    
    public String eliminarMateria(int id_materia){
        String msj,cadenaSQL;
        EntityMateria entMate = new EntityMateria();
        cadenaSQL="delete from MATERIA where id_materia="+id_materia+";";
        msj = entMate.EjecutarComando(cadenaSQL);
        return msj;
    }
    
     public String modificarMateria(int id_materia,String codigo,String nombre,int id_plan){
        String msj,cadenaSQL;
        EntityMateria entMate = new EntityMateria();
        cadenaSQL="update MATERIA set cod_asignatura='"+codigo+"', "
                + "nombre_materia ='"+nombre+"',PLAN_id_plan="+id_plan+" "
                + "where id_materia="+id_materia+"";
        msj = entMate.EjecutarComando(cadenaSQL);
        return msj;
    }
}
